package pw_math

import (
	"fmt"
	"github.com/dengsgo/math-engine/engine"
)

func Exec(exp string) {
	// input text -> []token
	toks, err := engine.Parse(exp)
	if err != nil {
		fmt.Println("ERROR: " + err.Error())
		return
	}
	// []token -> AST Tree
	ast := engine.NewAST(toks, exp)
	if ast.Err != nil {
		fmt.Println("ERROR: " + ast.Err.Error())
		return
	}
	// AST builder
	ar := ast.ParseExpression()
	if ast.Err != nil {
		fmt.Println("ERROR: " + ast.Err.Error())
		return
	}
	// AST traversal -> result
	r := engine.ExprASTResult(ar)
	fmt.Printf("%s = %v\n", exp, r)
}
